package com.cat.greedyAlgorithm;

import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-initial-energy-to-finish-tasks/
 * @create 2025/10/8 15:06
 * @since JDK17
 */

public class Solution54 {
    public int minimumEffort(int[][] tasks) {
        Arrays.sort(tasks, (a, b) -> (b[0] - b[1]) - (a[0] - a[1]));
        int ans = 0;
        for (var task : tasks) {
            ans = Math.max(task[1], task[0] + ans);
        }
        return ans;
    }
}
